<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>标签管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加标签</el-breadcrumb-item>
    </el-breadcrumb>
<el-card>

        <el-row :gutter="20">
            <el-col :span="8">
          <el-input
            placeholder="请输入新建标签关键字"
            v-model="queryInfo.title"
            clearable
            @clear=""
            @click=""
          >

          </el-input>
        </el-col>

        <el-col :span="7">
          <el-date-picker
            v-model="timeRange.lasttime"
            type="daterange"
            range-separator="至"
            start-placeholder="标签有效期起始"
            end-placeholder="标签有效期截至"
            value-format="yyyy-MM-dd"
          >
            >
          </el-date-picker>
        </el-col>

        <el-col :span="1">
          <el-button type="primary" @click="insertLabel()" icon="el-icon-search"
            >加入新标签</el-button
          >
        </el-col>

      </el-row>

    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 查询条件
      queryInfo: {
        title: '',
        starttime: null,
        endtime: null
      },

      // 时间起始
      timeRange: {
        lasttime: null
      }

    }
  },
  created () {
    // 加载页面时 加载一次数据

  },
  methods: {
    async insertLabel () {
      this.queryInfo.createtime = this.timeRange.lasttime[0]
      this.queryInfo.endtime = this.timeRange.lasttime[1]

      let title = this.queryInfo.title
      let createtime = this.queryInfo.createtime
      let endtime = this.queryInfo.endtime

      //  console.log(this.queryInfo.title)
      // console.log(this.lasttime)
      const { data: res } = await this.$http.post(
        'label/insert',
        { 'title': title, 'createtime': createtime, 'endtime': endtime }, {
          headers: {
            'content-type': 'application/json',
            'X-Request-With': 'XMLHttpRequest',
            'token': window.sessionStorage.getItem('token')
          }
        }
      )

      if (res.code !== 200) return this.$message.error('Error:' + res.message)
      return this.$message.success('新建标签成功')
    }

  },
  filters: {

  }
}
</script>

<style lang="less" scope>
</style>
